package praktikumid.w06.p3;

import java.util.ArrayList;
import java.util.List;

public class Main {

	public static void main(String[] args) {
		
		Car c1; // no new object is created
		c1 = new Car("123ABC", 4); // new -> object is created in memory
		
		List<Vehicle> vehicles = new ArrayList<Vehicle>();
		vehicles.add(c1);
		vehicles.add(new Motorcycle("M12", true));
		vehicles.add(new Motorcycle("mk1", false));
		vehicles.add(new Car("666klr", 2));
		vehicles.add(new Car("864ghj"));
		
		for (Vehicle v : vehicles) {
			if (v instanceof Car) {
				// current element is Car (not motorcycle)
				Car c = (Car) v; // let's cast v into Car
				System.out.println("Car");
				System.out.println(v.toString());
				System.out.println("doors:" + c.getNumberOfDoors());
			} else if (v instanceof Motorcycle) {
				// motorcycle
				Motorcycle m = (Motorcycle) v;
				System.out.println("Motorcycle");
				System.out.println(m.toString());
				System.out.println("has sidecar:" + m.hasSidecar());
			}
			/* 
			 * ideally, Car and Motorcycle classes could
			 * just override toString method
			 * to print necessary information.
			 * That way the code here would look cleaner.
			 * We woulnd't need casting, we can just use:
			 * v.toString();
			 * or even System.out.println(v);
			 */
		}
	}

}
